var typeid = 0;
var List = [];
var startDate = '';
var endDate = '';
var editUserId = 0;
var newscore = 0;
var userid = 0;

var title = '';
var username = '';


//分页查询
var limit = 5;// 每页多少条
var currPage = 1;// 当前页
var allPage = 1;// 总页数
var count = 0;// 默认共多少条数据



function getstartDate(){
	startDate = document.getElementById('start').value;
	
	
}
function getendDate(){
	endDate = document.getElementById('end').value;
	
}



function getlist(){
	$.ajax({
		url : ajax_host +'getCheckFile.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
				List = resp.list;
				console.log("列表："+List);
				renderTable(resp.list);
			}
		}
	})
}

function doSend(){
	title = $('#title').val();
	username = $('#username').val();
	selectCheckFile();
}

selectCheckFile();
function selectCheckFile(){
	console.log(startDate);
	console.log(endDate);


	$.ajax({
		url:ajax_host+'selectCheckFile.act',
		dataType : 'JSON',
		data:{
			title : title,
            username : username,
			start : startDate,
			end : endDate,
			startpage : currPage,
			limitpage : limit
		},
		success:function(resp){
			
			if(resp.success){
				List = resp.list;
				console.log("查询后列表："+List);
				renderTable(resp.list);
				// 总页数=记录数/每页记录
				count = resp.count;
				console.log('总记录数:'+count)
				allPage=count%limit==0?(count/limit):(parseInt(count/limit+1));
				console.log('总页数:'+allPage);
				$("#pager").html(currPage+"/"+allPage);
			}else{
				layer.alert(resp.errmsg);
			}
        }
	})
}
function renderTable(arr){
	var str = `<tr>
	<th>寄件人</th>
    <th>快件单号</th>
	<th>快件名</th>
    <th>收件人</th>
    <th>审核状态</th>
    <th>快件目的地</th>
    <th>快件类型</th>
	<th>快件费用</th>
	<th>寄件所在网点</th>
	<th>操作</th>
	</tr>`;
	for(var i = 0;i<arr.length;i++){
		var a = arr[i];
		str += 
		   `<tr>
		   <td>${a.uName}</td>
		   <td>${a.eId}</td>
		   <td>${a.eName}</td>
		   <td>${a.aTtn}</td>
		   <td>`;
		   if(a.cId == 1) str +='待审核';
		   if(a.cId == 2) str +='审核通过';
		   if(a.cId == 3) str +='审核不通过';
		   str +=`</td>
		   <td>${a.dest}</td>
		   <td>${a.tName}</td>
		   <td>${a.tMoney}</td>
		   <td>${a.uNidame}</td>
			<td>
            <a href = "###" onclick="doUpdate(${i},${a.eId},${a.tMoney})">进行审核</a>
			</td>
		</tr>`;
		
	}
	html('table',str);
}

function doUpdate(index,fId,score){
    console.log("遮罩获取列表："+List);
	
    console.log("获取的fid:"+fId);
    console.log("获取的对应类型积分:"+score);
    $('#doUpdate').modal({
        show:true,//展示出来
        moveable:true,//可移动
        rememberPos:true,//记住移动位置
		backdrop:'static'//背景遮罩
	});
    var user = List[index];
    userid = user.uId;
    editUserId = fId;
    newscore = score;
	console.log('user的值为'+user);
    console.log('edit的值为'+editUserId);
    console.log('userid的值为'+userid);
    var radios = document.getElementsByName('status1');
	for(var i = 0; i<radios.length; i++){
		if(radios[i].value == user.state){//判断value和我们的值是否相等
			
			radios[i].checked = true;		
			
		}
	}
}

function confirm2(){
	//  $('#doUpdate').modal('hide', 'fit');
	$.ajax({
		url:ajax_host+'checkExpress.act',
		type : 'post',
		dataType:'JSON',
		data:{
            userid : userid,
			newscore : newscore,
			status : val('status1','radio'),
			eid : editUserId

		},
		success:function(resp){
			
			if(resp.success){
				//关闭遮罩
				$('#doUpdate').modal('hide', 'fit');
				layer.alert('修改成功');
				selectCheckFile();
			}else{
				$('#doUpdate').modal('hide', 'fit');
				layer.alert(resp.errmsg);
			}
		}
})
}




function pagenext() {
	if (currPage + 1 > allPage) {
		layer.alert("当前已经是最后一页");
		return;
	}

	currPage = currPage + 1;
	selectCheckFile();
};

function pageback() {
	if (currPage - 1 == 0) {
		layer.alert("当前已经是第一页");
		return;
	}
	
	currPage = currPage - 1;
	selectCheckFile();
};